<?php
/**票付通对接票联
*2015-11-17 10:10
*by pzp
*测试环境接口地址：http://116.255.207.71:8080/utws/services/FSalerService?wsdl
*账户：FXTEST
*密钥：8c59d1214a659a7a6c277d371f8173d6
*商品名称：重渡沟景区
商品编码：SP000004
商品价格：95
*/
include('/var/www/html/new/d/module/api/PiaoLian/PiaoLian.class.php');
include('/var/www/html/new/d/module/api/function.class.php');

if (!class_exists("go_sql")){
	include("/var/www/html/new/conf/le.je");
	$le=new go_sql();
	$le->connect();
}

$txt=json_encode($_REQUEST);
$PFT_infunction = new AllFunction();
$logdata= $txt;
$func_res = 'get_data';
$PFT_infunction->logfile("$merchnum|".$logdata,$func_res);

if(!isset($_REQUEST['Action']) && $_REQUEST['PayStatus'] == 1 ){ //下单
	$timestart = microtime(true);
	if(!$_REQUEST['TicketID']) exit("101|0|0|0|0|0");
	$tid = $_REQUEST['TicketID'] + 0; //门票id
	$select_uuid = "select t.uuid,t.pid,l.apply_did,m.account from uu_jq_ticket as t, uu_land as l,pft_member as m where l.id = t.landid and t.id=$tid and l.apply_did=m.id limit 1";
	
	$GLOBALS['le']->query($select_uuid);
	if(!$GLOBALS['le']->fetch_assoc())	exit("101");		
	$uuid = $GLOBALS['le']->f('uuid');  //查询票类id	
	$pid = $GLOBALS['le']->f('pid');  
	$apply_did = $GLOBALS['le']->f('apply_did'); 
	$lid = $GLOBALS['le']->f('landid'); 
	$account = $GLOBALS['le']->f('account'); 
	
	$pl = new PiaoLian($apply_did);
	
	$get_ghprice = $PFT_infunction->Dynamic_Price_And_Storage($account,$pid,substr($_REQUEST['PlayDate'],0,10),1,$apply_did);  //获取零售价
	$get_ghprice_xml = simplexml_load_string($get_ghprice);
	$ghprice = (string)$get_ghprice_xml->Rec->UUsprice / 100 ;
	
	$ls_order = 'pft'.str_replace('.',mt_rand(1000,9999),microtime(true));	
	$request_array = array(
		'pftordernum'	=> $ls_order,
		'ispay'			=> 1,	
		'UUplaytime'	=> substr($_REQUEST['PlayDate'],0,10),
		'pftordername'	=> $_REQUEST['TouristName'],
		'IDcar'			=> $_REQUEST['IdCard'],
		'UUordertel'	=> $_REQUEST['TouristTel'],
		'uuid'			=> $uuid,
		'tprice'		=> $ghprice,
		'UUtnum'		=> $_REQUEST['Tnum']
	);		
	$agencyOrderAdd  = $pl->agencyOrderAdd($request_array,$PFT_infunction);
	if($agencyOrderAdd == 101)  exit("101");
	else exit("200|0|0|0|".$agencyOrderAdd['ECode']."|".$agencyOrderAdd['platOrderNo'].'_'.$ls_order);
}
elseif($_REQUEST['Action'] == 'Relation'){ //下单成功

	$Ordern = $_REQUEST['Ordern'];
	$pft_order_xml = $PFT_infunction->Select_PFTorder($_REQUEST['Ordern']);
	$tnum = (int)$pft_order_xml->Rec->UUtnum;
	$UUvcode = (string)$pft_order_xml->Rec->UUvcode;
	$tordernums = explode('_',(string)$pft_order_xml->Rec->UUtordernum);
	$apiOrder = $tordernums['0'];
	$tempOrder = $tordernums['1'];

	$str="insert into all_api_order (pftOrder,apiOrder,tempOrder,coopB,oStatus,oStnum,apiCode,handleStatus,cTime) values('$Ordern','$apiOrder','$tempOrder',14,0,$tnum,'$UUvcode',0,now())";
	$GLOBALS['le']->query($str);
}
elseif($_REQUEST['Action'] == 'MOD'){//取消订单

	$pftOrder = $_REQUEST['Ordern'];
	$selapiOrder = "select apiOrder,tempOrder,oStatus,oStnum from all_api_order where pftOrder='$pftOrder' limit 1";
	$GLOBALS['le']->query($selapiOrder);
	if(!$GLOBALS['le']->fetch_assoc())	exit('105');
	$tempOrder = $GLOBALS['le']->f('tempOrder');
	$apiOrder = $GLOBALS['le']->f('apiOrder');
	$oStatus = $GLOBALS['le']->f('oStatus');
	$oStnum = $GLOBALS['le']->f('oStnum');
	
	$pft_order_xml = $PFT_infunction->Select_PFTorder($pftOrder);
	$tid = (int)$pft_order_xml->Rec->UUtid;
	$UUaids=	(string)$pft_order_xml->Rec->UUaids;
	if($UUaids == 0){
		$UUaid = (int)$pft_order_xml->Rec->UUaid;
	}else{
		$UUaidss= explode(',',$UUaids);
		$UUaid = $UUaidss[0];
	}
	
	$pl = new PiaoLian($UUaid);
	
	$seluuid = "select uuid from uu_jq_ticket where id=$tid limit 1";
	$GLOBALS['le']->query($seluuid);
	$GLOBALS['le']->fetch_assoc();
	$uuid = $GLOBALS['le']->f('uuid');

	$modify_array = array(
		'APIOrdern'	=> $apiOrder,
		'editMode'	=> 1,
		'uuid'		=> $uuid,
		'productNum'	=> $_REQUEST['Tnum']
	);
	
	$EditOrderNum  = $pl->EditOrderNum($modify_array,$PFT_infunction);
	$oStatus = 4;
	if($_REQUEST['Tnum'] == 0) $oStatus = 3;
	if($EditOrderNum == 100){ 
		$str="update all_api_order set oStatus=$oStatus,oStnum=".$_REQUEST['Tnum'].", handleStatus=0 where pftOrder='".$_REQUEST['Ordern']."' limit 1";
		$GLOBALS['le']->query($str);	
		exit("200");
	}
	else{ // 处理失败
		$str="update all_api_order set oStatus=$oStatus,oStnum=".$_REQUEST['Tnum'].", handleStatus=1 where pftOrder='".$_REQUEST['Ordern']."' limit 1";
		$GLOBALS['le']->query($str);
		exit("1077");
	}
}
?>